import { DataSource } from 'typeorm';
import config from '../app.config';

export const U9Repository = new DataSource({
  type: 'mssql',
  host: config.U9DB.HOST ? config.U9DB.HOST : '192.168.1.201',
  port: config.U9DB.PORT ? Number(config.U9DB.PORT) : 1433,
  username: config.U9DB.USERNAME ? config.U9DB.USERNAME : 'sa',
  password: config.U9DB.PASSWORD ? config.U9DB.PASSWORD : 'THxxb@2021+21.',
  database: config.U9DB.DATABASE ? config.U9DB.DATABASE : 'THKJ',
  extra: { trustServerCertificate: true },
  // logging: ['query'], // 启用日志记录
});

// 初始化数据库连接
U9Repository.initialize()
  .then(() => {
    console.log('Data Source has been initialized!');
  })
  .catch((err) => {
    console.error('Error during Data Source initialization', err);
  });
